// Copyright (c) Lawrence Livermore National Security, LLC and other VisIt
// Project developers.  See the top-level LICENSE file for dates and other
// details.  No copyright assignment is required to contribute to VisIt.

#include <PyColorControlPointList.h>
#include <ObserverToCallback.h>
#include <stdio.h>
#include <Py2and3Support.h>
#include <PyColorControlPoint.h>

// ****************************************************************************
// Module: PyColorControlPointList
//
// Purpose:
//   This class contains a list of ColorControlPoint objects.
//
// Note:       Autogenerated by xml2python. Do not modify by hand!
//
// Programmer: xml2python
// Creation:   omitted
//
// ****************************************************************************

//
// This struct contains the Python type information and a ColorControlPointList.
//
struct ColorControlPointListObject
{
    PyObject_HEAD
    ColorControlPointList *data;
    bool        owns;
    PyObject   *parent;
};

//
// Internal prototypes
//
static PyObject *NewColorControlPointList(int);
std::string
PyColorControlPointList_ToString(const ColorControlPointList *atts, const char *prefix, const bool forLogging)
{
    std::string str;
    char tmpStr[1000];

    { // new scope
        int index = 0;
        if (forLogging)
        {
            // this is needed in case the current NumControlPoints is greater
            // than the default set up by the containing class.
            snprintf(tmpStr, 1000, "SetNumControlPoints(%d)\n",
                atts->GetNumControlPoints());
            str += (prefix + std::string(tmpStr));
        }
        // Create string representation of controlPoints from atts.
        for(AttributeGroupVector::const_iterator pos = atts->GetControlPoints().begin(); pos != atts->GetControlPoints().end(); ++pos, ++index)
        {
            const ColorControlPoint *current = (const ColorControlPoint *)(*pos);
            snprintf(tmpStr, 1000, "GetControlPoints(%d).", index);
            std::string objPrefix(prefix + std::string(tmpStr));
            str += PyColorControlPoint_ToString(current, objPrefix.c_str(), forLogging);
        }
        if(index == 0)
            str += "#controlPoints does not contain any ColorControlPoint objects.\n";
    }
    const char *smoothing_names = "NONE, Linear, CubicSpline";
    switch (atts->GetSmoothing())
    {
      case ColorControlPointList::None:
          snprintf(tmpStr, 1000, "%ssmoothing = %sNONE  # %s\n", prefix, prefix, smoothing_names);
          str += tmpStr;
          break;
      case ColorControlPointList::Linear:
          snprintf(tmpStr, 1000, "%ssmoothing = %sLinear  # %s\n", prefix, prefix, smoothing_names);
          str += tmpStr;
          break;
      case ColorControlPointList::CubicSpline:
          snprintf(tmpStr, 1000, "%ssmoothing = %sCubicSpline  # %s\n", prefix, prefix, smoothing_names);
          str += tmpStr;
          break;
      default:
          break;
    }

    if(atts->GetEqualSpacingFlag())
        snprintf(tmpStr, 1000, "%sequalSpacingFlag = 1\n", prefix);
    else
        snprintf(tmpStr, 1000, "%sequalSpacingFlag = 0\n", prefix);
    str += tmpStr;
    if(atts->GetDiscreteFlag())
        snprintf(tmpStr, 1000, "%sdiscreteFlag = 1\n", prefix);
    else
        snprintf(tmpStr, 1000, "%sdiscreteFlag = 0\n", prefix);
    str += tmpStr;
    {   const stringVector &tagNames = atts->GetTagNames();
        snprintf(tmpStr, 1000, "%stagNames = (", prefix);
        str += tmpStr;
        for(size_t i = 0; i < tagNames.size(); ++i)
        {
            snprintf(tmpStr, 1000, "\"%s\"", tagNames[i].c_str());
            str += tmpStr;
            if(i < tagNames.size() - 1)
            {
                snprintf(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        snprintf(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    return str;
}

static PyObject *
ColorControlPointList_Notify(PyObject *self, PyObject *args)
{
    ColorControlPointListObject *obj = (ColorControlPointListObject *)self;
    obj->data->Notify();
    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ColorControlPointList_GetControlPoints(PyObject *self, PyObject *args)
{
    ColorControlPointListObject *obj = (ColorControlPointListObject *)self;
    int index = -1;
    if (args == NULL)
        return PyErr_Format(PyExc_NameError, "Use .GetControlPoints(int index) to get a single entry");
    if (!PyArg_ParseTuple(args, "i", &index))
        return PyErr_Format(PyExc_TypeError, "arg must be a single integer index");
    if (index < 0 || (size_t)index >= obj->data->GetControlPoints().size())
        return PyErr_Format(PyExc_ValueError, "index out of range");

    // Since the new object will point to data owned by the this object,
    // we need to increment the reference count.
    Py_INCREF(self);

    PyObject *retval = PyColorControlPoint_Wrap(&obj->data->GetControlPoints(index));
    // Set the object's parent so the reference to the parent can be decref'd
    // when the child goes out of scope.
    PyColorControlPoint_SetParent(retval, self);

    return retval;
}

PyObject *
ColorControlPointList_GetNumControlPoints(PyObject *self, PyObject *args)
{
    ColorControlPointListObject *obj = (ColorControlPointListObject *)self;
    return PyInt_FromLong((long)obj->data->GetControlPoints().size());
}

PyObject *
ColorControlPointList_AddControlPoints(PyObject *self, PyObject *args)
{
    ColorControlPointListObject *obj = (ColorControlPointListObject *)self;
    PyObject *element = NULL;
    if(!PyArg_ParseTuple(args, "O", &element))
        return NULL;
    if(!PyColorControlPoint_Check(element))
        return PyErr_Format(PyExc_TypeError, "expected attr object of type ColorControlPoint");
    ColorControlPoint *newData = PyColorControlPoint_FromPyObject(element);
    obj->data->AddControlPoints(*newData);
    obj->data->SelectControlPoints();
    Py_INCREF(Py_None);
    return Py_None;
}

static PyObject *
ColorControlPointList_Remove_One_ControlPoints(PyObject *self, int index)
{
    ColorControlPointListObject *obj = (ColorControlPointListObject *)self;
    // Remove in the AttributeGroupVector instead of calling RemoveControlPoints() because we don't want to delete the object; just remove it.
    AttributeGroupVector &atts = obj->data->GetControlPoints();
    AttributeGroupVector::iterator pos = atts.begin();
    // Iterate through the vector "index" times.
    for(int i = 0; i < index; ++i)
        ++pos;

    // If pos is still a valid iterator, remove that element.
    if(pos != atts.end())
    {
        // NOTE: Leak the object since other Python objects may reference it. Ideally,
        // we would put the object into some type of pool to be cleaned up later but
        // this will do for now.
        //
        // delete *pos;
        atts.erase(pos);
    }

    obj->data->SelectControlPoints();
    Py_INCREF(Py_None);
    return Py_None;
}

PyObject *
ColorControlPointList_RemoveControlPoints(PyObject *self, PyObject *args)
{
    int index = -1;
    if(!PyArg_ParseTuple(args, "i", &index))
        return PyErr_Format(PyExc_TypeError, "Expecting integer index");
    ColorControlPointListObject *obj = (ColorControlPointListObject *)self;
    if(index < 0 || index >= obj->data->GetNumControlPoints())
        return PyErr_Format(PyExc_IndexError, "Index out of range");

    return ColorControlPointList_Remove_One_ControlPoints(self, index);
}

PyObject *
ColorControlPointList_ClearControlPoints(PyObject *self, PyObject *args)
{
    ColorControlPointListObject *obj = (ColorControlPointListObject *)self;
    int n = obj->data->GetNumControlPoints();
    for(int i = 0; i < n; ++i)
    {
        ColorControlPointList_Remove_One_ControlPoints(self, 0);
        Py_DECREF(Py_None);
    }
    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ColorControlPointList_SetSmoothing(PyObject *self, PyObject *args)
{
    ColorControlPointListObject *obj = (ColorControlPointListObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if ((val == -1 && PyErr_Occurred()) || long(cval) != val)
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }

    if (cval < 0 || cval >= 3)
    {
        std::stringstream ss;
        ss << "An invalid smoothing value was given." << std::endl;
        ss << "Valid values are in the range [0,2]." << std::endl;
        ss << "You can also use the following symbolic names:";
        ss << " None";
        ss << ", Linear";
        ss << ", CubicSpline";
        return PyErr_Format(PyExc_ValueError, ss.str().c_str());
    }

    Py_XDECREF(packaged_args);

    // Set the smoothing in the object.
    obj->data->SetSmoothing(ColorControlPointList::SmoothingMethod(cval));

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ColorControlPointList_GetSmoothing(PyObject *self, PyObject *args)
{
    ColorControlPointListObject *obj = (ColorControlPointListObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetSmoothing()));
    return retval;
}

/*static*/ PyObject *
ColorControlPointList_SetEqualSpacingFlag(PyObject *self, PyObject *args)
{
    ColorControlPointListObject *obj = (ColorControlPointListObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    bool cval = bool(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ bool");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ bool");
    }

    Py_XDECREF(packaged_args);

    // Set the equalSpacingFlag in the object.
    obj->data->SetEqualSpacingFlag(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ColorControlPointList_GetEqualSpacingFlag(PyObject *self, PyObject *args)
{
    ColorControlPointListObject *obj = (ColorControlPointListObject *)self;
    PyObject *retval = PyInt_FromLong(obj->data->GetEqualSpacingFlag()?1L:0L);
    return retval;
}

/*static*/ PyObject *
ColorControlPointList_SetDiscreteFlag(PyObject *self, PyObject *args)
{
    ColorControlPointListObject *obj = (ColorControlPointListObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    bool cval = bool(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ bool");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ bool");
    }

    Py_XDECREF(packaged_args);

    // Set the discreteFlag in the object.
    obj->data->SetDiscreteFlag(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ColorControlPointList_GetDiscreteFlag(PyObject *self, PyObject *args)
{
    ColorControlPointListObject *obj = (ColorControlPointListObject *)self;
    PyObject *retval = PyInt_FromLong(obj->data->GetDiscreteFlag()?1L:0L);
    return retval;
}

/*static*/ PyObject *
ColorControlPointList_SetTagNames(PyObject *self, PyObject *args)
{
    ColorControlPointListObject *obj = (ColorControlPointListObject *)self;

    stringVector vec;

    if (PyUnicode_Check(args))
    {
        char const *val = PyUnicode_AsUTF8(args);
        std::string cval = std::string(val);
        if (val == 0 && PyErr_Occurred())
        {
            PyErr_Clear();
            return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ string");
        }
        vec.resize(1);
        vec[0] = cval;
    }
    else if (PySequence_Check(args))
    {
        vec.resize(PySequence_Size(args));
        for (Py_ssize_t i = 0; i < PySequence_Size(args); i++)
        {
            PyObject *item = PySequence_GetItem(args, i);

            if (!PyUnicode_Check(item))
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_TypeError, "arg %d is not a unicode string", (int) i);
            }

            char const *val = PyUnicode_AsUTF8(item);
            std::string cval = std::string(val);

            if (val == 0 && PyErr_Occurred())
            {
                Py_DECREF(item);
                PyErr_Clear();
                return PyErr_Format(PyExc_TypeError, "arg %d not interpretable as C++ string", (int) i);
            }
            Py_DECREF(item);

            vec[i] = cval;
        }
    }
    else
        return PyErr_Format(PyExc_TypeError, "arg(s) must be one or more string(s)");

    obj->data->GetTagNames() = vec;
    // Mark the tagNames in the object as modified.
    obj->data->SelectTagNames();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ColorControlPointList_GetTagNames(PyObject *self, PyObject *args)
{
    ColorControlPointListObject *obj = (ColorControlPointListObject *)self;
    // Allocate a tuple the with enough entries to hold the tagNames.
    const stringVector &tagNames = obj->data->GetTagNames();
    PyObject *retval = PyTuple_New(tagNames.size());
    for(size_t i = 0; i < tagNames.size(); ++i)
        PyTuple_SET_ITEM(retval, i, PyString_FromString(tagNames[i].c_str()));
    return retval;
}


PyObject *
ColorControlPointList_SetNumControlPoints(PyObject *self, PyObject *args)
{
    ColorControlPointListObject *obj = (ColorControlPointListObject *)self;
    int numItems = -1;
    if(!PyArg_ParseTuple(args, "i", &numItems))
        return PyErr_Format(PyExc_TypeError, "Expecting integer argument");
    obj->data->SetNumControlPoints(numItems);
    Py_INCREF(Py_None);
    return Py_None;
}


PyMethodDef PyColorControlPointList_methods[COLORCONTROLPOINTLIST_NMETH] = {
    {"Notify", ColorControlPointList_Notify, METH_VARARGS},
    {"GetControlPoints", ColorControlPointList_GetControlPoints, METH_VARARGS},
    {"GetNumControlPoints", ColorControlPointList_GetNumControlPoints, METH_VARARGS},
    {"AddControlPoints", ColorControlPointList_AddControlPoints, METH_VARARGS},
    {"RemoveControlPoints", ColorControlPointList_RemoveControlPoints, METH_VARARGS},
    {"ClearControlPoints", ColorControlPointList_ClearControlPoints, METH_VARARGS},
    {"SetSmoothing", ColorControlPointList_SetSmoothing, METH_VARARGS},
    {"GetSmoothing", ColorControlPointList_GetSmoothing, METH_VARARGS},
    {"SetEqualSpacingFlag", ColorControlPointList_SetEqualSpacingFlag, METH_VARARGS},
    {"GetEqualSpacingFlag", ColorControlPointList_GetEqualSpacingFlag, METH_VARARGS},
    {"SetDiscreteFlag", ColorControlPointList_SetDiscreteFlag, METH_VARARGS},
    {"GetDiscreteFlag", ColorControlPointList_GetDiscreteFlag, METH_VARARGS},
    {"SetTagNames", ColorControlPointList_SetTagNames, METH_VARARGS},
    {"GetTagNames", ColorControlPointList_GetTagNames, METH_VARARGS},
    {"SetNumControlPoints", ColorControlPointList_SetNumControlPoints, METH_VARARGS},
    {NULL, NULL}
};

//
// Type functions
//

static void
ColorControlPointList_dealloc(PyObject *v)
{
   ColorControlPointListObject *obj = (ColorControlPointListObject *)v;
   if(obj->parent != 0)
       Py_DECREF(obj->parent);
   if(obj->owns)
       delete obj->data;
}

static PyObject *ColorControlPointList_richcompare(PyObject *self, PyObject *other, int op);
PyObject *
PyColorControlPointList_getattr(PyObject *self, char *name)
{
#include <visit-config.h>
    if(strcmp(name, "controlPoints") == 0)
        return ColorControlPointList_GetControlPoints(self, NULL);
    if(strcmp(name, "smoothing") == 0)
        return ColorControlPointList_GetSmoothing(self, NULL);
    if(strcmp(name, "None") == 0)
        return PyInt_FromLong(long(ColorControlPointList::None));
    if(strcmp(name, "NONE") == 0)
        return PyInt_FromLong(long(ColorControlPointList::None));
    if(strcmp(name, "Linear") == 0)
        return PyInt_FromLong(long(ColorControlPointList::Linear));
    if(strcmp(name, "CubicSpline") == 0)
        return PyInt_FromLong(long(ColorControlPointList::CubicSpline));

    if(strcmp(name, "equalSpacingFlag") == 0)
        return ColorControlPointList_GetEqualSpacingFlag(self, NULL);
    if(strcmp(name, "discreteFlag") == 0)
        return ColorControlPointList_GetDiscreteFlag(self, NULL);
    if(strcmp(name, "tagNames") == 0)
        return ColorControlPointList_GetTagNames(self, NULL);

#if VISIT_OBSOLETE_AT_VERSION(3,5,0)
#error This code is obsolete in this version. Please remove it.
#else
    // Try and handle legacy fields in ColorControlPointList

    //
    // Removed in 3.3.0
    //
    if(strcmp(name, "categoryName") == 0)
    {
        PyErr_WarnEx(NULL,
                    "categoryName is no longer a valid ColorControlPointList "
                    "attribute.\nIt's value is being ignored, please remove "
                    "it from your script.\n", 3);
        return PyString_FromString("");
    }
#endif

    // Add a __dict__ answer so that dir() works
    if (!strcmp(name, "__dict__"))
    {
        PyObject *result = PyDict_New();
        for (int i = 0; PyColorControlPointList_methods[i].ml_meth; i++)
            PyDict_SetItem(result,
                PyString_FromString(PyColorControlPointList_methods[i].ml_name),
                PyString_FromString(PyColorControlPointList_methods[i].ml_name));
        return result;
    }

    return Py_FindMethod(PyColorControlPointList_methods, self, name);
}

int
PyColorControlPointList_setattr(PyObject *self, char *name, PyObject *args)
{
#include <visit-config.h>
    PyObject NULL_PY_OBJ;
    PyObject *obj = &NULL_PY_OBJ;

    if(strcmp(name, "smoothing") == 0)
        obj = ColorControlPointList_SetSmoothing(self, args);
    else if(strcmp(name, "equalSpacingFlag") == 0)
        obj = ColorControlPointList_SetEqualSpacingFlag(self, args);
    else if(strcmp(name, "discreteFlag") == 0)
        obj = ColorControlPointList_SetDiscreteFlag(self, args);
    else if(strcmp(name, "tagNames") == 0)
        obj = ColorControlPointList_SetTagNames(self, args);

#if VISIT_OBSOLETE_AT_VERSION(3,5,0)
#error This code is obsolete in this version. Please remove it.
#else
    // Try and handle legacy fields in ColorControlPointList
    if(obj == &NULL_PY_OBJ)
    {
        //
        // Removed in 3.3.0
        //
        if(strcmp(name, "categoryName") == 0)
        {
            PyErr_WarnEx(NULL, "'categoryName' is obsolete. It is being ignored.", 3);
            Py_INCREF(Py_None);
            obj = Py_None;
        }
    }
#endif
    if (obj != NULL && obj != &NULL_PY_OBJ)
        Py_DECREF(obj);

    if (obj == &NULL_PY_OBJ)
    {
        obj = NULL;
        PyErr_Format(PyExc_NameError, "name '%s' is not defined", name);
    }
    else if (obj == NULL && !PyErr_Occurred())
        PyErr_Format(PyExc_RuntimeError, "unknown problem with '%s'", name);

    return (obj != NULL) ? 0 : -1;
}

static int
ColorControlPointList_print(PyObject *v, FILE *fp, int flags)
{
    ColorControlPointListObject *obj = (ColorControlPointListObject *)v;
    fprintf(fp, "%s", PyColorControlPointList_ToString(obj->data, "",false).c_str());
    return 0;
}

PyObject *
ColorControlPointList_str(PyObject *v)
{
    ColorControlPointListObject *obj = (ColorControlPointListObject *)v;
    return PyString_FromString(PyColorControlPointList_ToString(obj->data,"", false).c_str());
}

//
// The doc string for the class.
//
#if PY_MAJOR_VERSION > 2 || (PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION >= 5)
static const char *ColorControlPointList_Purpose = "This class contains a list of ColorControlPoint objects.";
#else
static char *ColorControlPointList_Purpose = "This class contains a list of ColorControlPoint objects.";
#endif

//
// Python Type Struct Def Macro from Py2and3Support.h
//
//         VISIT_PY_TYPE_OBJ( VPY_TYPE,
//                            VPY_NAME,
//                            VPY_OBJECT,
//                            VPY_DEALLOC,
//                            VPY_PRINT,
//                            VPY_GETATTR,
//                            VPY_SETATTR,
//                            VPY_STR,
//                            VPY_PURPOSE,
//                            VPY_RICHCOMP,
//                            VPY_AS_NUMBER)

//
// The type description structure
//

VISIT_PY_TYPE_OBJ(ColorControlPointListType,         \
                  "ColorControlPointList",           \
                  ColorControlPointListObject,       \
                  ColorControlPointList_dealloc,     \
                  ColorControlPointList_print,       \
                  PyColorControlPointList_getattr,   \
                  PyColorControlPointList_setattr,   \
                  ColorControlPointList_str,         \
                  ColorControlPointList_Purpose,     \
                  ColorControlPointList_richcompare, \
                  0); /* as_number*/

//
// Helper function for comparing.
//
static PyObject *
ColorControlPointList_richcompare(PyObject *self, PyObject *other, int op)
{
    // only compare against the same type 
    if ( Py_TYPE(self) != &ColorControlPointListType
         || Py_TYPE(other) != &ColorControlPointListType)
    {
        Py_INCREF(Py_NotImplemented);
        return Py_NotImplemented;
    }

    PyObject *res = NULL;
    ColorControlPointList *a = ((ColorControlPointListObject *)self)->data;
    ColorControlPointList *b = ((ColorControlPointListObject *)other)->data;

    switch (op)
    {
       case Py_EQ:
           res = (*a == *b) ? Py_True : Py_False;
           break;
       case Py_NE:
           res = (*a != *b) ? Py_True : Py_False;
           break;
       default:
           res = Py_NotImplemented;
           break;
    }

    Py_INCREF(res);
    return res;
}

//
// Helper functions for object allocation.
//

static ColorControlPointList *defaultAtts = 0;
static ColorControlPointList *currentAtts = 0;

static PyObject *
NewColorControlPointList(int useCurrent)
{
    ColorControlPointListObject *newObject;
    newObject = PyObject_NEW(ColorControlPointListObject, &ColorControlPointListType);
    if(newObject == NULL)
        return NULL;
    if(useCurrent && currentAtts != 0)
        newObject->data = new ColorControlPointList(*currentAtts);
    else if(defaultAtts != 0)
        newObject->data = new ColorControlPointList(*defaultAtts);
    else
        newObject->data = new ColorControlPointList;
    newObject->owns = true;
    newObject->parent = 0;
    return (PyObject *)newObject;
}

static PyObject *
WrapColorControlPointList(const ColorControlPointList *attr)
{
    ColorControlPointListObject *newObject;
    newObject = PyObject_NEW(ColorControlPointListObject, &ColorControlPointListType);
    if(newObject == NULL)
        return NULL;
    newObject->data = (ColorControlPointList *)attr;
    newObject->owns = false;
    newObject->parent = 0;
    return (PyObject *)newObject;
}

///////////////////////////////////////////////////////////////////////////////
//
// Interface that is exposed to the VisIt module.
//
///////////////////////////////////////////////////////////////////////////////

PyObject *
ColorControlPointList_new(PyObject *self, PyObject *args)
{
    int useCurrent = 0;
    if (!PyArg_ParseTuple(args, "i", &useCurrent))
    {
        if (!PyArg_ParseTuple(args, ""))
            return NULL;
        else
            PyErr_Clear();
    }

    return (PyObject *)NewColorControlPointList(useCurrent);
}

//
// Plugin method table. These methods are added to the visitmodule's methods.
//
static PyMethodDef ColorControlPointListMethods[] = {
    {"ColorControlPointList", ColorControlPointList_new, METH_VARARGS},
    {NULL,      NULL}        /* Sentinel */
};

static Observer *ColorControlPointListObserver = 0;

std::string
PyColorControlPointList_GetLogString()
{
    std::string s("ColorControlPointList = ColorControlPointList()\n");
    if(currentAtts != 0)
        s += PyColorControlPointList_ToString(currentAtts, "ColorControlPointList.", true);
    return s;
}

static void
PyColorControlPointList_CallLogRoutine(Subject *subj, void *data)
{
    typedef void (*logCallback)(const std::string &);
    logCallback cb = (logCallback)data;

    if(cb != 0)
    {
        std::string s("ColorControlPointList = ColorControlPointList()\n");
        s += PyColorControlPointList_ToString(currentAtts, "ColorControlPointList.", true);
        cb(s);
    }
}

void
PyColorControlPointList_StartUp(ColorControlPointList *subj, void *data)
{
    if(subj == 0)
        return;

    currentAtts = subj;
    PyColorControlPointList_SetDefaults(subj);

    //
    // Create the observer that will be notified when the attributes change.
    //
    if(ColorControlPointListObserver == 0)
    {
        ColorControlPointListObserver = new ObserverToCallback(subj,
            PyColorControlPointList_CallLogRoutine, (void *)data);
    }

}

void
PyColorControlPointList_CloseDown()
{
    delete defaultAtts;
    defaultAtts = 0;
    delete ColorControlPointListObserver;
    ColorControlPointListObserver = 0;
}

PyMethodDef *
PyColorControlPointList_GetMethodTable(int *nMethods)
{
    *nMethods = 1;
    return ColorControlPointListMethods;
}

bool
PyColorControlPointList_Check(PyObject *obj)
{
    return (obj->ob_type == &ColorControlPointListType);
}

ColorControlPointList *
PyColorControlPointList_FromPyObject(PyObject *obj)
{
    ColorControlPointListObject *obj2 = (ColorControlPointListObject *)obj;
    return obj2->data;
}

PyObject *
PyColorControlPointList_New()
{
    return NewColorControlPointList(0);
}

PyObject *
PyColorControlPointList_Wrap(const ColorControlPointList *attr)
{
    return WrapColorControlPointList(attr);
}

void
PyColorControlPointList_SetParent(PyObject *obj, PyObject *parent)
{
    ColorControlPointListObject *obj2 = (ColorControlPointListObject *)obj;
    obj2->parent = parent;
}

void
PyColorControlPointList_SetDefaults(const ColorControlPointList *atts)
{
    if(defaultAtts)
        delete defaultAtts;

    defaultAtts = new ColorControlPointList(*atts);
}

